package com.iot.manage.service;

import com.alibaba.fastjson.JSONObject;
import com.iot.manage.dao.LoginMapper;
import com.iot.manage.pojo.Menus;
import com.iot.manage.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LoginService {

    @Autowired
    private LoginMapper loginMapper;

    public List<Menus> findMenus() {
        //返回一级目录
        List<Menus> menusRootList = loginMapper.findRootMenus();
        for (int i = 0; i < menusRootList.size(); i++){
            //返回二级目录
            List<Menus> menusChildList = loginMapper.findChildMenus(menusRootList.get(i).getId());
            menusRootList.get(i).setChildren(menusChildList);
        }
        return menusRootList;
    }

    public List<User> findUserByName(JSONObject params) {
       return loginMapper.findUserByName(params);
    }

    public String findPassByName(JSONObject params) {
        return loginMapper.findPassByName(params);
    }
}
